home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / lisp / electric / echistory.el < prev    next >
Encoding:
Text File  |  1995-05-12  |  7.0 KB  |  172 lines

  1. ;;; echistory.el --- Electric Command History Mode
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Author: K. Shane Hartman
  6. ;; Maintainer: FSF
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Synched up with: FSF 19.28.
  25.  
  26. ;;; Code:
  27.  
  28. (require 'electric)            ; command loop
  29. (require 'chistory)            ; history lister
  30. (require 'helper)
  31.  
  32. ;;;###autoload
  33. (defun Electric-command-history-redo-expression (&optional noconfirm)
  34.   "Edit current history line in minibuffer and execute result.
  35. With prefix argument NOCONFIRM, execute current line as-is without editing."
  36.   (interactive "P")
  37.   (let (todo)
  38.     (save-excursion
  39.       (set-buffer "*Command History*")
  40.       (beginning-of-line)
  41.       (setq todo (read (current-buffer)))
  42.       (if (boundp 'electric-history-in-progress)
  43.       (if todo (throw 'electric-history-quit (list noconfirm todo)))))))
  44.  
  45. (defvar electric-history-map ())
  46. (if electric-history-map
  47.     ()
  48.   (setq electric-history-map (make-keymap))
  49.   (set-keymap-name electric-history-map 'electric-history-map)
  50.   (let ((i 0))
  51.     (while (< i 128)
  52.       (define-key electric-history-map (make-string 1 i)
  53.     'Electric-history-undefined)
  54.       (setq i (1+ i))))
  55.   (let ((map (make-keymap))
  56.     (i 0))
  57.     ;;#### Urk!  There should be a better way in Lucid Emacs!
  58.     (define-key electric-history-map "\e" map)
  59.     (while (< i 128)
  60.       (define-key map (make-string 1 i) 'Electric-history-undefined)
  61.       (setq i (1+ i))))
  62.   (define-key electric-history-map "\C-u" 'universal-argument)
  63.   (define-key electric-history-map " " 'Electric-command-history-redo-expression)
  64.   (define-key electric-history-map "!" 'Electric-command-history-redo-expression)
  65.   (define-key electric-history-map "\e\C-x" 'eval-sexp)
  66.   (define-key electric-history-map "\e\C-d" 'down-list)
  67.   (define-key electric-history-map "\e\C-u" 'backward-up-list)
  68.   (define-key electric-history-map "\e\C-b" 'backward-sexp)
  69.   (define-key electric-history-map "\e\C-f" 'forward-sexp)
  70.   (define-key electric-history-map "\e\C-a" 'beginning-of-defun)
  71.   (define-key electric-history-map "\e\C-e" 'end-of-defun)
  72.   (define-key electric-history-map "\e\C-n" 'forward-list)
  73.   (define-key electric-history-map "\e\C-p" 'backward-list)
  74.   (define-key electric-history-map "q" 'Electric-history-quit)
  75.   (define-key electric-history-map "\C-c" nil)
  76.   (define-key electric-history-map "\C-c\C-c" 'Electric-history-quit)
  77.   (define-key electric-history-map "\C-]" 'Electric-history-quit)
  78.   (define-key electric-history-map "\C-z" 'suspend-emacs)
  79. ;;  (define-key electric-history-map "\C-h" 'Helper-help)
  80.   (define-key electric-history-map '(control h) 'Helper-help)
  81.   (define-key electric-history-map 'backspace 'previous-line)
  82.   (define-key electric-history-map "?" 'Helper-describe-bindings)
  83.   (define-key electric-history-map "\e>" 'end-of-buffer)
  84.   (define-key electric-history-map "\e<" 'beginning-of-buffer)
  85.   (define-key electric-history-map "\n" 'next-line)
  86.   (define-key electric-history-map "\r" 'next-line)
  87.   (define-key electric-history-map "\177" 'previous-line)  
  88.   (define-key electric-history-map "\C-n" 'next-line)
  89.   (define-key electric-history-map "\C-p" 'previous-line)
  90.   (define-key electric-history-map "\ev" 'scroll-down)
  91.   (define-key electric-history-map "\C-v" 'scroll-up)
  92.   (define-key electric-history-map [home] 'beginning-of-buffer)
  93.   (define-key electric-history-map [down] 'next-line)
  94.   (define-key electric-history-map [up] 'previous-line)
  95.   (define-key electric-history-map [prior] 'scroll-down)
  96.   (define-key electric-history-map [next] 'scroll-up)
  97.   (define-key electric-history-map "\C-l" 'recenter)
  98.   (define-key electric-history-map "\e\C-v" 'scroll-other-window))
  99.  
  100. (defvar electric-command-history-hook nil
  101.   "If non-nil, its value is called by `electric-command-history'.")
  102.  
  103. ;;;###autoload
  104. (defun electric-command-history ()
  105.   "\\<electric-history-map>Major mode for examining and redoing commands from `command-history'.
  106. This pops up a window with the Command History listing.
  107. The number of command listed is controlled by `list-command-history-max'.
  108. The command history is filtered by `list-command-history-filter' if non-nil.
  109. Combines typeout Command History list window with menu like selection
  110. of an expression from the history for re-evaluation in the *original* buffer.
  111.  
  112. The history displayed is filtered by `list-command-history-filter' if non-nil.
  113.  
  114. This pops up a window with the Command History listing.  If the very
  115. next character typed is Space, the listing is killed and the previous
  116. window configuration is restored.  Otherwise, you can browse in the
  117. Command History with  Return  moving down and  Delete  moving up, possibly
  118. selecting an expression to be redone with Space or quitting with `Q'.
  119.  
  120. Like Emacs-Lisp mode except that characters do not insert themselves and
  121. Tab and Linefeed do not indent.  Instead these commands are provided:
  122. \\{electric-history-map}
  123.  
  124. Calls the value of `electric-command-history-hook' if that is non-nil.
  125. The Command History listing is recomputed each time this mode is invoked."
  126.   (interactive)
  127.   (let ((electric-history-in-progress t)
  128.     (old-buffer (current-buffer))
  129.     (todo))
  130.     (unwind-protect
  131.     (setq todo
  132.           (catch 'electric-history-quit
  133.         (save-window-excursion
  134.           (save-window-excursion
  135.             (list-command-history)
  136.             (set-buffer "*Command History*")
  137.             (Command-history-setup 'electric-command-history
  138.                        "Electric History"
  139.                        electric-history-map))
  140.           (Electric-pop-up-window "*Command History*")
  141.           (run-hooks 'electric-command-history-hook)
  142.           (if (eobp)
  143.               (progn (ding)
  144.                  (message "No command history.")
  145.                  (throw 'electric-history-quit nil))
  146.             (let ((Helper-return-blurb "return to History"))
  147.               (Electric-command-loop 'electric-history-quit
  148.                          "->" t))))))
  149.       (set-buffer "*Command History*")
  150.       (Command-history-setup)
  151.       (bury-buffer (current-buffer)))
  152.     (if (consp todo)
  153.     (progn (set-buffer old-buffer)
  154.            (if (car todo)
  155.            (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
  156.          (edit-and-eval-command "Redo: " (car (cdr todo))))))))
  157.  
  158. (defun Electric-history-undefined ()
  159.   (interactive)
  160.   (ding)
  161.   (message (substitute-command-keys "Type \\[Helper-help] for help, ? for commands, C-c C-c to quit, Space to execute"))
  162.   (sit-for 4))
  163.  
  164. (defun Electric-history-quit ()
  165.   "Quit Electric Command History, restoring previous window configuration."
  166.   (interactive)
  167.   (if (boundp 'electric-history-in-progress)
  168.       (progn (message nil)
  169.          (throw 'electric-history-quit nil))))
  170.  
  171. ;;; echistory.el ends here
  172.